import React, { Component } from 'react';
import { Card, Button, Divider, message, Spin, Icon } from 'antd';
import { connect } from 'dva';
import request from '@/utils/request';

const antIcon = <Icon type="loading" style={{ fontSize: 13 }} spin />;
class IframeView extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
    };
  }

  render() {
    return (
      <Card
        title="usoflow模板管理"
        className="cute"
        extra={
          <>
            <Spin indicator={antIcon} spinning={this.state.loading} style={{ paddingRight: 4 }} />
            <a
              onClick={() => {
                this.setState({
                  loading: true,
                });
                request('pmc/pms/UosFlowController/synFlow', {
                  method: 'GET',
                }).then(res => {
                  if (res.success) {
                    message.success('同步成功');
                    this.setState({
                      loading: false,
                    });
                  } else {
                    message.error(res.errMessage);
                  }
                });
              }}
            >
              同步
            </a>
            <Divider type="vertical" />
            <a
              onClick={() => {
                this.props.goToStep(1);
                if (this.props.type === 'config') {
                  this.props.queryTreeData();
                } else if (this.props.type === 'add') {
                  this.props.refresh();
                }
              }}
            >
              返回
            </a>
          </>
        }
      >
        <iframe
          title="iframe"
          src="http://172.16.81.126:8849/uos-manager/ssologin.do?language=zh&account=bsc&bpId=&goto=/flowDefineManage?frame=0&privCode=flowDefineManage"
          frameBorder="0"
          height={this.props.size.height - 76}
          width="100%"
          // style={{ backgroundColor: '#fff' }}
        />
      </Card>
    );
  }
}

export default connect(({ setting }) => ({
  size: setting.size,
}))(IframeView);
